<template>
	<view class="list">
		<view class="item" :id="item.id" v-for="(item, index) in list" :key="index">
			<view class="item_img">
				<image :src="imgUrl + item.image" />
			</view>
			<view class="item_title">{{ item.name }}</view>
			<view class="bot-btns">
				<navigator class="btn1" :url="'/pages/vote/index?vote_id=' + item.id" hover-class="none">示例</navigator>
				<view class="btn2" @click="create(index)" :class="color+'-bg'">创建活动</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex';
	export default {
		computed: {
			...mapGetters({
				imgUrl: 'common/cdnurl',
				color: 'common/color',
				color_value: 'common/color_value',
				system: 'common/system',
			})
		},
		data() {
			return {
				list: [],
				mold: 1,
			};
		},
		onLoad(options) {
			this.mold = options.mold ? options.mold : 1;
			this.http('vote/temp', '', 'get').then(res => {
				this.list = res.data;
			});
			// #ifdef MP-WEIXIN
			this.adUtils.cp.load('vote_temp')
			uni.$u.mpShare = {
				title: this.system.share_title,
				path: '/pages/index/index',
				imageUrl: this.imgUrl + this.system.share_img
			}
			// #endif
			this.utils.share()
		},
		onShow() {
			if (getApp().globalData.audio) {
				getApp().globalData.audio.destroy();
				getApp().globalData.audio = null;
			}
		},
		methods: {
			create(index) {
				var item = this.list[index];
				this.utils.goto('/pages/save/save?temp_name=' + item.temp_name + '&mold=' + this.mold + '&image=' + item
					.image);
			}
		}
	};
</script>

<style lang="scss">
	.list {
		width: 100%;
		display: flex;
		align-content: flex-start;
		flex-wrap: wrap;
		padding: 10px;
	}

	.item {
		width: 48%;
		background: #fff;
		padding: 10px;
		margin-bottom: 10px;
		margin-left: 1%;
		margin-right: 1%;
		position: relative;
		border-radius: 15px;
		box-shadow: 2px 2px 3px rgba(26, 26, 26, 0.2);
	}

	.item_img image {
		width: 98%;
		height: 120px;
		display: block;
		margin: 0 auto;
		border-radius: 15px;
	}

	.item_title {
		width: 100%;
		height: 40px;
		line-height: 40px;
		text-align: center;
		overflow: hidden;
		font-weight: bold;
	}

	.bot-btns {
		width: 100%;
		text-align: center;
		display: flex;
		justify-content: space-between;
	}

	.bot-btns navigator,
	.bot-btns view {
		width: 48%;
		height: 30px;
		line-height: 30px;
		font-size: 12px;
	}

	.btn1 {
		display: inline-block;
		border: 1px solid #ddd;
		border-radius: 15px;
	}

	.btn2 {
		display: inline-block;
		color: #fff;
		border-radius: 15px;
	}
</style>
